﻿Imports WeifenLuo.WinFormsUI.Docking

Public Class DownloadImageFromWebFrom
  Inherits DockContent

  Private _w As DownloadabeWallpaper

  Private Sub Download(ByVal url As String, ByVal name As String)
    Dim i As Image
    Dim s() As String = url.Split("/")
    _w = ServiceManager.GetServiceManager.GetWallpaperService.GetNewDownloadableWallpaper
    _w.Filename = s(s.Length - 1)
    _w.URL = url
    _w.Name = name
    _w.Datum = Date.Now
    _w.OrgaID = -1
    _w.DownloadFile(False)
    i = Image.FromFile(Configuration.GetObject.SkinsPath & _w.Filename)
    _w.Resolution = i.Width & "x" & i.Height
    ServiceManager.GetServiceManager.GetWallpaperService.InsertNewWallpaper(DirectCast(_w, Wallpaper))
    Dim lvi As ListViewItem = Me.HistoryListView.Items.Add(_w.FullName)
    lvi.SubItems.Add(_w.Filename)
    lvi.SubItems.Add(_w.Resolution)
    i.Dispose()
  End Sub

  Private Sub DownloadButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DownloadButton.Click
    Download(Me.LinkTextBox.Text, NameTextBox.Text)
    LinkTextBox.Text = ""
    NameTextBox.Text = ""
    Refresh()
  End Sub
End Class